#!/usr/bin/env bash
#
#
#disk number
disk_b=`lsblk -rf  |awk '$2 == "ntfs"{print $1}'`
disk_n=`lsblk -rf  |awk '$2 == "ntfs"{print $1}'|wc -l`

#disk ==> filename
dir=/tmp/data
data1=$dir/disk1234
data2=$dir/disk5678
data3=$dir/fdisk9101112
data4=$dir/fdisk01
data5=$dir/fdisk03
data6=$dir/fdisk05
data7=$dir/fdisk07
data8=$dir/fdisk09
data=($data1 $data2 $data3 $data4 $data5 $data6 $data7 $data8)
data_m=(/mnt/data1 /mnt/data2 /mnt/data3 /mnt/data4 /mnt/data5 /mnt/data6 /mnt/data7 /mnt/data8)

#mount dirname

function check_file() {
    local number=0
    for d in ${data[*]}
    do
        ismount=$(df -h |grep ${data_m[$number]})
        if [ -n "$ismount" ];then
            number=$(($number+1))
            continue
        fi
        if [ -d $d ];then
            echo $number
            return
        fi
        number=$(($number+1))
    done
    echo 8
    return
}

function blk_mount() {
    [ -d $dir ] || mkdir $dir
    for i in ${disk_b[*]}
    do
        mount -t ntfs-3g /dev/$i $dir
        if [ $? -eq 0 ];then
            local n=`check_file`
            if [ $n -lt 8 ];then
            umount $dir && {
                mount -t ntfs-3g -o defaults,noatime /dev/$i ${data_m[$n]}
		#k=`basename ${data_m[$n]}`
             #   echo -e "\033[32;1m mount -t ntfs-3g /dev/$i $dir/${data_m[$n]}\033[0m"
               # blk=`blkid /dev/$i`
               # uuid=`echo $blk |awk 'NR==1{for(n=1;n<NF;n++){if($n~"UUID"){print $n}}}' |cut -c 6-`
               # sed -i '/'$k'/d' /etc/fstab
               # echo "UUID=$uuid ${data_m[$n]} ntfs-3g defaults,noatime 0 0">> /etc/fstab
	    }
            else
                umount $dir
            fi
        else
	    umount $dir
        fi
    done           
}

function symbol_link() {
    m=$(df -h |grep data |wc -l)
    if [ $m -ge 8 ];then
        ln -sf /mnt/data2/ad  /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/File /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/grade /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/Img /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/Media /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/MV /home/bxroot/vod_api/data/

        ln -sf /mnt/data3/diskBNS/bns /home/bxroot/vod_api/data/song/
        ln -sf /mnt/data3/diskBNS/ad /home/bxroot/vod_api/data/song/
        ln -sf /mnt/data1/disk1234/disk01 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/disk1234/disk02 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/disk1234/disk03 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/disk1234/disk04 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk05 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk06 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk07 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk08 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk09 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk10 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk11 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk13 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/diskBNS/dj /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data4/fdisk01 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data4/fdisk02 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data5/fdisk03 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data5/fdisk04 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data6/fdisk05 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data6/fdisk06 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data7/fdisk07 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data7/fdisk08 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data8/fdisk09 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data8/fdisk10 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data7/fdisk11 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data8/fdisk12 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/fdisk9101112/fdisk13 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/diskBNS/xin /home/bxroot/vod_api/data/song/
    else
        ln -sf /mnt/data2/ad  /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/File /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/grade /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/Img /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/Media /home/bxroot/vod_api/data/
        ln -sf /mnt/data2/MV /home/bxroot/vod_api/data/

        ln -sf /mnt/data3/diskBNS/bns /home/bxroot/vod_api/data/song/
        ln -sf /mnt/data3/diskBNS/ad /home/bxroot/vod_api/data/song/
        ln -sf /mnt/data1/disk1234/disk01 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/disk1234/disk02 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/disk1234/disk03 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/disk1234/disk04 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk05 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk06 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk07 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/disk5678/disk08 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk09 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk10 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk11 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/disk910xin/disk13 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/diskBNS/dj /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/fdisk1234/fdisk01 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/fdisk1234/fdisk02 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/fdisk1234/fdisk03 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data1/fdisk1234/fdisk04 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/fdisk5678/fdisk05 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/fdisk5678/fdisk06 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/fdisk5678/fdisk07 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data2/fdisk5678/fdisk08 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/fdisk9101112/fdisk09 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/fdisk9101112/fdisk10 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/fdisk9101112/fdisk11 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/fdisk9101112/fdisk12 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/fdisk9101112/fdisk13 /home/bxroot/vod_api/data/song/
	ln -sf /mnt/data3/diskBNS/xin /home/bxroot/vod_api/data/song/
    fi
}

blk_mount
symbol_link
